<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 300px;
      margin: 100px auto;
      /* background-color: skyblue; */
    }

    .box button {
      display: block;
      width: 100px;
      height: 30px;
      margin: 0 auto;
    }

    #canvas {
      width: 300px;
      height: 300px;
    }
  </style>
</head>

<body>
  <div class="box">
    <button onclick="draw()">调用调色板</button>
    <canvas id="canvas"></canvas>
  </div>

  <script>
    function draw() {
      const canvas = document.querySelector('#canvas')
      const canvas2d = canvas.getContext('2d')
      for (let i = 0; i < 20; i++) {
        for (let j = 0; j < 20; j++) {
          canvas2d.fillStyle = `rgb(${Math.floor(255-13.42*i)}, ${Math.floor(255-13.42*j)}, 0)`
          canvas2d.fillRect(j * 15, i * 15, 15, 15)
        }
      }
    }
  </script>
</body>

</html>